; ---------- intro
author Marco Bresciani
name NCC-1701-A
password xxxxxxxxxxxxxx
iff code xxxxxxxxxxxxxx
debug off

raise shield
; ---------- main cycle
LCARS:
; ---------- starting check
 long range scan
 if scan found enemy then gosub LongFight
 if scan found flag then gosub FlagTake
; ---------- perimeter check
 scan perimeter
 if scan found enemy then gosub EnergyFight
 if scan found nothing then move forward
 if scan found nothing then gosub TurnAround
 if scan found nothing then move forward
 generate random
 if random is 1 then gosub TurnAround
; ---------- forward check
 scan forward
 if scan found enemy then gosub ShortFight
 if scan found flag then gosub FlagTake
 if scan found nothing then move forward
 if scan found nothing then move forward
; ---------- side check
 generate random
 if random is 4 then gosub Side
; ---------- short forward check
 scan relative 1
 if scan found nothing then move forward
 if scan found enemy then gosub ShortFight
 if scan found barrier then gosub TurnAround
 if scan found mine then gosub TurnAround
; ---------- cybug check
 if damage is > 60 then gosub Repairing
 if no ammo then gosub FlagSearch
 if fuel is > 15 then goto LCARS
; ---------- full stop
NoFuel:
 gosub TurnAround
 scan perimeter
 if scan found enemy then self destruct
 long range scan
 if scan found enemy then gosub LongFight
 if scan found friend then beep
goto NoFuel

; ---------- short range attack
ShortFight:
 lower shield
 fire weapon
 fire weapon
 fire weapon
 raise shield
 lay mines on
 move backward
 lay mines off
return

; ---------- long range attack
LongFight:
 lower shield
 if missile ready then launch missile
 if missile ready then launch missile
 raise shield
return

; ---------- capture the flag
FlagTake:
 if damage is = 0 then discharge energy
subFlagTake:
 move forward
 scan forward
 if scan found enemy then gosub ShortFight
 scan relative 1
 if scan found barrier then return
 if damage is > 0 then goto subFlagTake
return

; ---------- flag search
FlagSearch:
 long range scan
 if scan found flag then gosub FlagTake
 if ammo is > 0 then return
 scan forward
 if scan found flag then gosub FlagTake
 if scan found nothing then move forward
 scan perimeter
 if scan found enemy then self destruct
 gosub TurnAround
 goto FlagSearch
return

; ---------- rotate
TurnAround:
 generate random
 goto #random
1:
 turn right
return
2:
 turn right
return
3:
 turn left
return
4:
 turn left
return

; ---------- sides check
Side:
 turn right
 long range scan
 if scan found flag then gosub FlagTake
 if scan found flag then return
 if scan found enemy then gosub LongFight
 turn left
 turn left
 long range scan
 if scan found flag then gosub FlagTake
 if scan found flag then return
 if scan found enemy then gosub LongFight
 turn right
return

; ---------- repair cybug
Repairing:
 lower shield
 attempt repairs
 raise shield
 generate random
 if random is 1 then move forward
 if random is 2 then turn right
 if random is 3 then turn left
 if random is 4 then move backward
 long range scan
 if scan found flag then gosub subFlagTake
 if scan found enemy then gosub LongFight
 if fuel is < 10 then gosub NoFuel
 if fuel is < 45 then return
 if damage is > 40 then goto Repairing
return

; ---------- energy discharge
EnergyFight:
 if damage is < 65 then discharge energy
 scan perimeter
 if scan found enemy then goto EnergyFight
 cross scan
 if scan found flag then goto FlagCross
 corner scan
 if scan found flag then goto FlagCorner
return
FlagCross:
 scan relative 1
 if scan found nothing then turn right
 if scan found nothing goto FlagCross
 if scan found flag then move forward
return
FlagCorner:
 move forward
subFlagCorner:
 scan right
 if scan found flag then turn right
 if scan found flag then move forward
 if scan found flag then return
 scan left
 if scan found flag then turn left
 if scan found flag then move forward
 if scan found flag then return
 move backward
 move backward
 goto subFlagCorner
return